/*
 * @Author: your name
 * @Date: 2024-04-10 16:43:49
 * @LastEditTime: 2024-04-10 16:57:51
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \.leetcode\1047.删除字符串中的所有相邻重复项.cpp
 */
/*
 * @lc app=leetcode.cn id=1047 lang=cpp
 *
 * [1047] 删除字符串中的所有相邻重复项
 */

// @lc code=start
class Solution {
public:
    string removeDuplicates(string s) {
        stack<char> st;
        if(s.size() < 2){
            return s;
        }
        for(char ss:s){
            if(!st.empty() && st.top() == ss ){
                st.pop();  
            }else{
                st.push(ss);
            }
        }
        int size = st.size();
        string res;
        if(size ==0) return res;
        res = string(size,0);
        while(!st.empty()){
            res[--size]=st.top();
            st.pop();
        }
        return res;

    }
};
// @lc code=end
// 用栈做比较
// 然后栈弹出，然后再反转一下
